#include "threadpool.h"

#include <iostream>
#include <thread>
#include <chrono>

int sum1(int a, int b)
{
    return a+b;
}


int main()
{
    ThreadPool pool;
    pool.start(1);
    //std::future<int> r1 = pool.submitTask(sum1, 1, 2);
    std::future<int> r2 = pool.submitTask([](int a, int b, int c)->int {
        // 任务提交失败
        std::this_thread::sleep_for(std::chrono::seconds(5));
        return a+b+c;}, 1, 2,3);
    std::future<int> r3 = pool.submitTask([](int a, int b, int c)->int {
        std::this_thread::sleep_for(std::chrono::seconds(5));
        return a+b+c;}, 1, 2,3);
    std::future<double> r4 = pool.submitTask([](double a, double b)-> double {
        std::this_thread::sleep_for(std::chrono::seconds(5));
        return a+b;}, 1.1, 2.3);
    //std::cout << r1.get() << std::endl;
    std::cout << r2.get() << std::endl;
    std::cout << r3.get() << std::endl;
    std::cout << r4.get() << std::endl;
    return 0;
}

#if 0
int main()
{
    ThreadPool pool;
    pool.setMode(PoolMode::MODE_CACHED);
    pool.start(2);
    std::future<int> r1 = pool.submitTask(sum1, 1, 2);
    std::future<int> r2 = pool.submitTask([](int a, int b, int c)->int {return a+b+c;}, 1, 2,3);
    std::future<int> r3 = pool.submitTask([](int a, int b, int c)->int {return a+b+c;}, 1, 2,3);
    std::future<int> r4 = pool.submitTask([](int a, int b, int c)->int {return a+b+c;}, 1, 2,3);
    std::future<int> r5 = pool.submitTask([](int a, int b, int c)->int {return a+b+c;}, 1, 2,3);
    std::future<int> r6 = pool.submitTask([](int a, int b, int c)->int {return a+b+c;}, 1, 2,3);
    std::future<int> r7 = pool.submitTask([](int a, int b, int c)->int {return a+b+c;}, 1, 2,3);
    std::cout << r1.get() << std::endl;
    std::cout << r2.get() << std::endl;
    std::cout << r3.get() << std::endl;
    std::cout << r4.get() << std::endl;
    std::cout << r5.get() << std::endl;
    std::cout << r6.get() << std::endl;
    std::cout << r7.get() << std::endl;
    return 0;
}
#endif